<script lang="ts" setup>
import { ref } from 'vue'
const { fn } = defineProps<{ fn: Function }>()
// 上传图片
const fileList = ref([]);
const afterRead = (file: any) => {
  file.status = 'uploading';
  file.message = '上传中...';
  let formData = new FormData();
  formData.append('file', file.file)
  fn(formData).then(() => {
    file.status = 'success';
    file.message = '上传成功';
  }).catch(() => {
    file.status = 'failed';
    file.message = '上传失败';
  })
}
</script>
<!--
  :fn = 上传图片的接口
  <comUploader :fn="postUploadAPI"></comUploader>
 -->
<template>
  <van-uploader v-model="fileList" :after-read="afterRead" />
</template>
<style lang="scss" scoped></style>
